﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="NullCacheProvider.cs" company="XamlNinja">
//   2011 Richard Griffin and Ollie Riches
// </copyright>
// <summary>
//   A Null Object Pattern Implementation Storage Cache Provider
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace WP7Contrib.Caching
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    /// <summary>
    /// The null cache provider - implementation of the null object pattern
    /// </summary>
    public sealed class NullCacheProvider : ICacheProvider
    {
        #region ICacheProvider Members

        /// <summary>
        /// Add a value to the cache with a relative expiry time, e.g 10 minutes.
        /// </summary>
        /// <typeparam name="TKey">
        /// The type of the key.
        /// </typeparam>
        /// <typeparam name="TValue">
        /// The type of the value.
        /// </typeparam>
        /// <param name="key">
        /// The key value.
        /// </param>
        /// <param name="value">
        /// The value, can be null.
        /// </param>
        /// <param name="relativeTime">
        /// The relative date time when the key value pair should expire and be purged from the cache.
        /// </param>
        public void Add<TKey, TValue>(TKey key, TValue value, TimeSpan relativeTime) where TValue : class
        {
        }

        /// <summary>
        /// Add a value to the cache with an absolute time, e.g. 01/01/2020.
        /// </summary>
        /// <typeparam name="TKey">
        /// The type of the key.
        /// </typeparam>
        /// <typeparam name="TValue">
        /// The type of the value.
        /// </typeparam>
        /// <param name="key">
        /// The key value.
        /// </param>
        /// <param name="value">
        /// The value, can be null.
        /// </param>
        /// <param name="absoluteTime">
        /// The absolute date time when the cache should expire and be purged the value.
        /// </param>
        public void Add<TKey, TValue>(TKey key, TValue value, DateTime absoluteTime) where TValue : class
        {
        }

        /// <summary>
        /// Gets a value from the cache.
        /// </summary>
        /// <typeparam name="TKey">
        /// The type of the key.
        /// </typeparam>
        /// <typeparam name="TValue">
        /// The type of the value.
        /// </typeparam>
        /// <param name="key">
        /// The key associated with value.
        /// </param>
        /// <returns>
        /// If the key exists in the cache then the value is returned, if the key does not exist then null is returned.
        /// </returns>
        public TValue Get<TKey, TValue>(TKey key) where TValue : class
        {
            return null;
        }

        /// <summary>
        /// Remove a value from the cache.
        /// </summary>
        /// <param name="key">
        /// The key associated with the value.
        /// </param>
        /// <typeparam name="TKey">
        /// The type of the key.
        /// </typeparam>
        public void Remove<TKey>(TKey key)
        {
        }

        /// <summary>
        /// Clears the contents of the cache.
        /// </summary>
        public void Clear()
        {
        }

        /// <summary>
        /// Nothing to preemptively do for this caching implementation
        /// </summary>
        public void PreemptiveInitialise()
        {

        }

        /// <summary>
        /// Returns true alkways
        /// </summary>
        /// <typeparam name="T">The type of the value.</typeparam>
        /// <param name="value">The value to checkd for cachability.</param>
        /// <returns>Returns true if the value can be added to the cache.</returns>
        public bool IsCacheable<T>(T value, ref IEnumerable<Type> failingTypes) where T : class
        {
            return true;
        }

        /// <summary>
        /// Returns an enumerator with no elements.
        /// </summary>
        /// <typeparam name="TKey">The type of the key.</typeparam>
        /// <returns>Returns an enumerator for keys of a specific type.</returns>
        public IEnumerable<TKey> Keys<TKey>()
        {
            return Enumerable.Empty<TKey>();
        }

        #endregion
    }
}